package cn.assumejson.springframework.context.context.annotation;

import cn.assumejson.springframework.beans.factory.support.RootBeanDefinition;
import cn.assumejson.springframework.context.context.support.GenericApplicationContext;
import cn.hutool.core.lang.Assert;

import java.beans.Introspector;

/**
 * 注解
 *
 * @author Mr. Li
 * @version 1.0
 * @since 1.0 2021/12/4 18:16
 */
public class AnnotationConfigApplicationContext extends GenericApplicationContext implements AnnotationConfigRegistry {

    /**
     * 在Spring 源码中，初始化
     */
    private final AnnotatedBeanDefinitionReader reader;

    /**
     * 类路径下的bean定义扫描器
     */
    private final ClassPathBeanDefinitionScanner scanner;


    public AnnotationConfigApplicationContext() {

        this.reader = new AnnotatedBeanDefinitionReader(this);

        this.scanner = new ClassPathBeanDefinitionScanner(this);
    }

    public AnnotationConfigApplicationContext(Class<?>... annotatedClasses) {
        //调用构造函数
        this();
        //注册我们的配置类
        register(annotatedClasses);
        //IOC容器刷新接口
        refresh();
    }


    @Override
    public void register(Class<?>... annotatedClasses) {
        Assert.notEmpty(annotatedClasses, "At least one component class must be specified");

        this.reader.register(annotatedClasses);
    }


    @Override
    public void scan(String... basePackages) {
        this.scanner.scan(basePackages);
    }
}
